/**
 * @program: malll
 * @description:
 * @author: Mr.Xu
 * @create: 2020-12-24 15:12
 **/

package com.bobo.mall.search.config;

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.elasticsearch.client.HttpAsyncResponseConsumerFactory;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 1、导入依赖
 * 2、编写配置类
 * 3、参考文档编写api
 * https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high.html
 */
@Configuration
public class MallElasticSearchConfig {

    /**
     * 设置请求设置项
     */
    public static final RequestOptions COMMON_OPTIONS;
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
        // 设置项
//        builder.addHeader("Authorizeation","Bearer"+Token);
//        builder.setHttpAsyncResponseConsumerFactory(
//                new HttpAsyncResponseConsumerFactory().HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024);
        COMMON_OPTIONS = builder.build();

    }


    /**
     *  高级别rest操作elasticsearch，底层封装的还是低端的rest
     * @return
     */
    @Bean
    public RestHighLevelClient  restHighLevelClient(){
        HttpHost host = new HttpHost("192.168.68.131", 9200, "http");
        RestClientBuilder builder = RestClient.builder(host);
        RestHighLevelClient client = new RestHighLevelClient(builder);
        return  client;
    }
}